<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;
use Illuminate\Database\Eloquent\SoftDeletes;

class OrderCartInfo extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     * 表中的类型状态 无
     */

    /**
     * 可搜索字段
     */
    public $searchable = [
        'cart_id',
        'order_id',
        'product_id',
        'unique',
        'cart_info',
    ];

    /**
     * 可批量赋值字段
     */
    public $fillable = [
        'cart_id',
        'order_id',
        'product_id',
        'unique',
        'cart_info',
    ];

    /**
     * 强制转换字段
     */
    public $casts = [
        'cart_info' => 'array'
    ];

    /**
     * 可排序字段
     */
    public $sortable = ['created_at', 'id'];

    /**
     * 默认排序字段
     */
    protected $defaultSortCriteria = ['id,desc'];


    /**
     * 关联的购物车
     */
    function cart(){
        return $this->belongsTo(Cart::class,'cart_id','id');
    }

    /**
     * 关联的商品
     */
    function product(){
        return $this->belongsTo(Product::class,'product_id','id');
    }
}
